package com.demo1;

import java.io.InputStream;
import java.net.Socket;

public class MyClient {

	public static void main(String[] args) throws Exception {
		//1.创建客户端对象
		Socket socket = new Socket("localhost",9001);
		//2.读取服务器返回的信息
		InputStream in = socket.getInputStream();
		//3.创建一个缓冲区
		byte [] buf = new byte[1024];
		//4.读取到字节数组--真实读取的长度
		int len = in.read(buf);
		//5.输出服务器返回的信息
		System.out.println("服务器说:"+ new String(buf,0,len) );
		socket.close();
	}

}
